var express = require("express");
var router = express.Router();

let { forlist, dyx_travel,dyx_history,dyx_pl_list} = require('../model/dyx_module')
 

router.get('/forlist',async(req,res)=>{
  let obj=await forlist.find()

  res.send({
    code: 200,
    data: obj
  })
})

router.post('/forlist', async (req, res) => {
  let obj = req.body
  await forlist.create(obj)
  res.send({
    code: 200,
    msg: '添加成功'
  })
})
router.delete('/dyx_history',async(req,res)=>{
  let id=req.query.id
  await dyx_history.deleteOne({_id:id})
  res.send({
    code: 200,
    msg: '删除成功'
  })
})

router.get('/dyx_history',async(req,res)=>{
  let obj=await dyx_history.find()
  res.send({
    code: 200,
    data: obj
  })
})

router.post('/dyx_history', async (req, res) => {
  let obj = req.body
  await dyx_history.create(obj)
  res.send({
    code: 200,
    msg: '添加成功'
  })
})

router.get('/dyx_travel', async (req, res) => {
  let obj = await dyx_travel.find()
  res.send({
    code: 200,
    data: obj
  })
})

router.post('/dyx_travel', async (req, res) => {
  let obj = req.body
  await dyx_travel.create(obj)
  res.send({
    code: 200,
    msg: '添加成功'
  })
})
router.get('/dyx_pl_list', async (req, res) => {
  let obj = await dyx_pl_list.find()
  res.send({
    code: 200,
    data: obj
  })
})

router.post('/dyx_addpl', async (req, res) => {
  let obj = req.body
  await dyx_pl_list.create(obj)
  res.send({
    code: 200,
    msg: '添加成功'
  })
})
module.exports = router;
